-
Notifications
You must be signed in to change notification settings - Fork 975
add example pico_w/wifi/ntp_system_time #716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
Thanks for the extra comments 👍 |
Oooo never considered that... My "lengthy and extensive research" (ha ha) suggests it might be the former: https://retrocomputing.stackexchange.com/questions/25601/what-is-the-meaning-of-asctime |
|
Found a way to avoid hardcoding the timezone names in the printf() :-) |
|
Many thanks for the excellent suggestions - should be all wrapped up in the latest commit (please let me know if I missed anything) |
|
Looking really good now - many thanks again for your time to review |
setenv() requires <stdlib.h> which is included via lwIP. Make it explicit in case someone uses the timezone code in a different context.
|
Spent far too long today chasing down why some simple test code couldn't find the function definition for |
|
I discovered this was giving very incorrect times of day when run on RP2040. This is because the aon_timer on that platform has a resolution of only one second, which is incompatible with SNTP round-trip compensation. To fix this I have added a test in the example's |
|
Looking at the RP2040 datasheet it seems like you could set up the RTC peripheral to trigger an interrupt once a minute (e.g. when the "seconds" value rolls around to 0), and then you could use the callback for that interrupt to read the current Timer peripheral value ("The system timer peripheral on RP2040 provides a global microsecond timebase for the system"). And then when you need the time with a smaller granularity than a second, you could re-read the timer again, subtract the value you stored in the callback, and that would give you the number of microseconds since the start of the last minute? (I guess it's very unlikely that an SNTP round-trip would take longer than a minute!) Of course it's entirely up to you to decide if it's worth adding that level of complexity to your example 😉 |
very inventive!
To be honest if anyone needs round-trip compensation that much it'd be more cost-effective to just send them a free Pico2_W! |
|
@lurch I was thinking more of the proposed method of adjusting the lwIP options depending on the platform (i.e. the condition in the CMakeLists.txt): I was wondering whether there was a more preferred way of doing that :-) |
A proposed new NTP example that differs from the existing
pico_w/wifi/ntp_clientin the following ways:pico_aon_timerto create a time-of-day clock that can be read asynchronously from user codeThe program connects to Wi-Fi, initialises the lwIP SNTP app, syncs the
pico_aon_timerto NTP and then enters a loop to display the local time in London (or UTC, or whichever timezone the user defines); resynchronising to ntp.pool.org in the background every hour.I suggest it's quite an important use case for the Pico-W, and illustrates a couple of features users may find helpful (such as how to create and use a POSIX timezone).